//
//  LDBaseCompanyIncKinds.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/5/9.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class LDBaseCompanyIncKinds: LDBaseTableViewVC {

    var titleArr = [String]()
    var title_idArr = [String]()
    var sendColsure:((index:Int,title:String)->Void)?
    var selIndex:Int?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        requestNet()
        setDefaultContent()
    }
    
    func requestNet() {
        
        LDCheckPublicInfo.shareInstance.checkoutAllJobIndustry { [weak self] (data) in
            
            for item in data {
                
                self?.titleArr.append(item["industry_name"]!)
                self?.title_idArr.append(item["industry_id"]!)
            }
            self?.tableView.reloadData()
        }
    }
    
    func setDefaultContent() {
        title = "公司行业"
    }
    
    override func tapRightBar() {
        
        if selIndex != nil {
            
<<<<<<< HEAD
            sendColsure!(index: selIndex!,title: titleArr[selIndex!])
=======
            let index = Int(title_idArr[selIndex!] ?? "0") ?? 0
            sendColsure!(index: index,title: titleArr[selIndex!])
>>>>>>> dingdong2.1.0
            navigationController?.popViewControllerAnimated(true)
            
        } else {
            
            showLDAlertView("没有选择标签")
        }
    }
    
    func getTitleFormCell(colsure:((index:Int,title:String) ->Void)) {
        
        dispatch_async(dispatch_get_main_queue(), {
            self.sendColsure = colsure
        })
        
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return titleArr.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier("cellindustry") as? LDBaseCompanyKindsCell
        
        if cell == nil {
            cell = LDBaseCompanyKindsCell.init(style: UITableViewCellStyle.Default, reuseIdentifier: "cellindustry")
        }
        cell?.titleLab?.text = titleArr[indexPath.row]
        return cell!
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        return 60
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        selIndex = indexPath.row
    }
}
